package com.ideaaedi.springcloud.jd.user.controller.sys;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.ideaaedi.springcloud.jd.commonds.entity.PageInfo;
import com.ideaaedi.springcloud.jd.commonds.entity.Result;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDataScopeListReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDataScopeUpdateReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDataScopeDetailRespVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDataScopeListRespVO;
import com.ideaaedi.springcloud.jd.user.service.SysDataScopeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 系统-数据操作范围
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2021.0.5.B
 */
@Validated
@RestController
@ApiSort(value = 13)
@RequestMapping("/sys-data-scope")
@Api(value = "系统-数据操作范围", tags = {"系统-数据操作范围"})
public class SysDataScopeController {
    
    @Resource
    private SysDataScopeService sysDataScopeService;
    
    /**
     * 改
     *
     * @param req 参数
     *
     * @return 修改后的数据详情
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "改")
    @PutMapping("/update")
    public Result<SysDataScopeDetailRespVO> update(@RequestBody @Validated SysDataScopeUpdateReqVO req) {
        return Result.success(sysDataScopeService.update(req));
    }
    
    /**
     * 查详情
     *
     * @param userId 用户id
     *
     * @return 数据详情
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查详情")
    @GetMapping("/detail-by-userId/{userId}")
    public Result<SysDataScopeDetailRespVO> detailByUserId(@ApiParam(value = "用户id", required = true)
                                                           @PathVariable("userId") @NotNull(message = "userId cannot be null.") Long userId) {
        return Result.success(sysDataScopeService.detailByUserId(userId));
    }
    
    /**
     * 查列表
     *
     * @param req 参数
     *
     * @return 数据列表
     */
    @ApiOperationSupport(order = 3)
    @PostMapping("/list")
    @ApiOperation(value = "查列表")
    public Result<PageInfo<SysDataScopeListRespVO>> list(@RequestBody @Validated SysDataScopeListReqVO req) {
        return Result.success(sysDataScopeService.list(req));
    }
    
}
